package com.lagou.mr.homework;

import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

public class NumberSort implements WritableComparable<NumberSort> {

    private Integer sort;

    private Integer number;

    public NumberSort() {
    }

    public NumberSort(Integer number) {
        this.number = number;
    }

    public NumberSort(Integer sort, Integer number) {
        this.sort = sort;
        this.number = number;
    }

    public Integer getSort() {
        return sort;
    }

    public void setSort(Integer sort) {
        this.sort = sort;
    }

    public Integer getNumber() {
        return number;
    }

    public void setNumber(Integer number) {
        this.number = number;
    }

    @Override
    public String toString() {
        return sort + "\t" + number ;
    }

    @Override
    public int compareTo(NumberSort o) {
        int i = 0;
        if (this.number > o.number){
            i = 1;
        }else if (this.number < o.number){
            i = -1;
        }else{
            i = 0;
        }
        return i;
    }

    @Override
    public void write(DataOutput out) throws IOException {
        out.writeInt(this.number);
    }

    @Override
    public void readFields(DataInput input) throws IOException {
        this.number = input.readInt();
    }
}
